<?php
	class phonggiaodichdb
	{
		public function Them($MaPhongGD = "", $TenPhongGD = "", $DiaDiemPhongGD = "", $DienThoai = "")
		{
			$sql = "INSERT INTO phonggiaodich(MaPhongGD, TenPhongGD, DiaDiemPhongGD, DienThoai)
						   VALUES('$MaPhongGD', '$TenPhongGD', '$DiaDiemPhongGD','$DienThoai')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongNhanVien($MaPhongGD = "")
		{
			$sql = "SELECT * FROM nguoidung WHERE 1";
			if($MaPhongGD != "")
				$sql.= " AND MaPhongGD = '$MaPhongGD'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaPhongGD = "", $TenPhongGD = "", $DiaDiemPhongGD = "", $DienThoai = "", $MaPhongGDCu = "")
		{
			$sql = "UPDATE phonggiaodich 
					SET TenPhongGD = '$TenPhongGD',
						DiaDiemPhongGD = '$DiaDiemPhongGD',
						DienThoai = '$DienThoai',
						MaPhongGD = '$MaPhongGD'
					WHERE MaPhongGD = '$MaPhongGDCu'";
			echo $sql;
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaPhongGD = "")
		{
			$sql = "DELETE FROM phonggiaodich 
					WHERE MaPhongGD = '$MaPhongGD'";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM phonggiaodich";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaPhongGD = "", $TenPhongGD = "", $DiaDiemPhongGD = "", $DienThoai = "")
		{
			$sql = "SELECT * 
					FROM phonggiaodich 
					WHERE 1";
			
			if($MaPhongGD != "")
				$sql .= " AND MaPhongGD = '$MaPhongGD'";
			
			if($TenPhongGD != "")
				$sql .= " AND TenPhongGD = '$TenPhongGD'";
			
			if($DiaDiemPhongGD != "")
				$sql .= " AND DiaDiemPhongGD = '$DiaDiemPhongGD'";
			
			if($DienThoai != "")
				$sql .= " AND DienThoai = '$DienThoai'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>